from django.db import models
from dvadmin.utils.models import CoreModel, table_prefix


class OpTypeList(CoreModel):
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name="算子类型名称", help_text="算子类型名称")

    class Meta:
        db_table = table_prefix + "optype_list"
        verbose_name = "算子种类管理"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)
class OpList(CoreModel):
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name="名称", help_text="名称")
    content = models.TextField(verbose_name="算子代码", help_text="算子代码")
    type = models.ForeignKey(OpTypeList, on_delete=models.PROTECT, null=True)
    params = models.CharField(max_length=200, null=True, blank=True, verbose_name="参数", help_text="参数")
    parameters = models.JSONField()

    def save(self, *args, **kwargs):
        super(OpList, self).save(*args, **kwargs)


    class Meta:
        db_table = table_prefix + "op_list"
        verbose_name = "算子管理"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)

class CameraList(CoreModel):
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name="摄像机名称", help_text="摄像机名称")
    url = models.CharField(max_length=200, null=True, blank=True, verbose_name="摄像机地址", help_text="摄像机地址")
    cameratype = models.IntegerField(default=0, verbose_name="摄像机类型", help_text="摄像机类型类型")

    def save(self, *args, **kwargs):
        super(CameraList, self).save(*args, **kwargs)

    class Meta:
        db_table = table_prefix + "camera_list"
        verbose_name = "摄像机管理"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)

class CameraScreenTypeList(CoreModel):
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name="名称", help_text="名称")
    url = models.CharField(max_length=200, null=True, blank=True, verbose_name="名称", help_text="名称")
    description = models.CharField(max_length=200, null=True, blank=True, verbose_name="描述", help_text="描述")
    interval =models.IntegerField(default=1, verbose_name="间隔", null=True, blank=True, help_text="间隔")
    screentype = models.IntegerField(default=1, verbose_name="截图类型", null=True, blank=True, help_text="截图类型")
    total = models.IntegerField(default=1, verbose_name="总数", null=True, blank=True, help_text="总数")
    # type = models.ForeignKey(CameraList, on_delete=models.PROTECT)

    def save(self, *args, **kwargs):
        super(CameraScreenTypeList, self).save(*args, **kwargs)

    class Meta:
        db_table = table_prefix + "camerascreentype_list"
        verbose_name = "取图信息管理"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)

class ScreenShotsList(CoreModel):
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name="截图名称", help_text="截图名称")
    src = models.CharField(max_length=200, null=True, blank=True, verbose_name="截图路径", help_text="截图路径")
    dir = models.CharField(max_length=200, null=True, blank=True, verbose_name="截图所在路径", help_text="截图所在路径")
    param1 = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="参数1",help_text="参数1")
    param2 = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="参数1",
                              help_text="参数2")

    class Meta:
        db_table = table_prefix + "screenshots_list"
        verbose_name = "视频截图列表"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)

class BucketList(CoreModel):
    source = models.CharField(max_length=200, null=True, blank=True, verbose_name="存储源", help_text="存储源")
    bucketname = models.CharField(max_length=200, null=True, blank=True, verbose_name="存储桶名称",
                                  help_text="存储桶名称")
    accesskey = models.CharField(max_length=200, null=True, blank=True, verbose_name="accesskey", help_text="accesskey")
    secretkey = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="secretkey",
                                 help_text="secretkey")
    spacename = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="存储空间名称",
                                 help_text="存储空间名称")
    accessurl = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="访问网址",
                                 help_text="访问网址")
    area = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="区域",
                            help_text="区域")
    suffix = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="网址后缀",
                              help_text="网址后缀")
    path = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="存储路径",
                            help_text="存储路径")
    appid = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="appid",
                             help_text="appid")
    version = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="版本",
                               help_text="版本")
    path = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="存储路径",
                            help_text="存储路径")
    param1 = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="param1",
                              help_text="param1")
    parma2 = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="param2",
                              help_text="param2")
    param3 = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="param3",
                              help_text="param3")
    parma4 = models.CharField(default="test", max_length=200, null=True, blank=True, verbose_name="params",
                              help_text="params")

    class Meta:
        db_table = table_prefix + "bucket_list"
        verbose_name = "存储桶列表"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)

class PictureTypeList(CoreModel):
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name="类型名称名称", help_text="类型名称")
    class Meta:
        db_table = table_prefix + "picturetype_list"
        verbose_name = "图片种类管理"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)
class PictureList(CoreModel):
    name = models.CharField(max_length=200, null=True, blank=True,unique=True, verbose_name="图片名称", help_text="图片名称")
    src = models.CharField(max_length=200, null=True, blank=True, verbose_name="图片路径", help_text="图片路径")
    dir = models.CharField(max_length=200, null=True, blank=True, verbose_name="图片所在路径", help_text="图片所在路径")
    type = models.ForeignKey(PictureTypeList, on_delete=models.CASCADE)
    class Meta:
        db_table = table_prefix + "picture_list"
        verbose_name = "图片列表"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)
